package com.itshen.jdk8.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Stream Demo
 */
public class StreamDemo {


    public static void main(String[] args) {
        Integer[] nums = {1, 2, 3, 4, 5, 6, 7};

        // Stream创建
        Stream.of(3, 2, 3, 4, 5, 6, 7, 8, 9).forEach(System.out::println);

        List<Integer> result1 = Arrays.stream(nums).map(x -> x * x).filter(x -> x > 5).collect(Collectors.toList());


        Integer[] result2 = Arrays.stream(nums).map(x -> x * x).filter(x -> x > 5).toArray(Integer[]::new);

        //
        Optional<Integer> result3 = Arrays.stream(nums).map(x -> x * x).filter(x -> x > 5).reduce((x, y) -> x + y);
    }

}
